const koaBody = require("koa-body");
const render = require("koa-art-template");
const path = require("path");
const requireDir = require("require-directory");
const Router = require("koa-router");
const static = require("koa-static")
function initProject(app) {
    requireDir(module, "../routers", { visit: loadRouters })
    function loadRouters(obj) {
        if (obj instanceof Router) {
            app.use(obj.routes())
        }
    }
    app.use(async (ctx, next) => {
        console.log(ctx.path)
        if (ctx.path == "/login" || ctx.path == "/doLogin") {
            await next();
        } else {
            if (ctx.cookies.get("login")) {
                await next();
            } else {
                await ctx.redirect("/login")
            }
        }
    })
    app.use(koaBody());
    render(app, {
        root: path.join(process.cwd(), 'pages'),
        extname: '.html',
        debug: process.env.NODE_ENV !== 'production'
    });
}
module.exports = initProject
    